﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// 文件名：ClsFeePayDAL.cs
/// 作  者：SAM
/// 时  间：2007-01-22
/// 说  明：ClsFeePayDAL类信息相关处理
/// </summary>
public class ClsFeePayDAL
{
    #region  费用支付数据访问层数据库连接部分
    /// <summary>
    /// 数据库连接字符串
    /// </summary>
    private static string strSqlConnectionString = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"];

    #endregion

    #region  费用支付数据访问层主体部分

    //获取所有费用支付信息
    public DataSet GetFeePay(string UserID, int Type)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetFeePay", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;

        dat.SelectCommand.Parameters.Add("@u_log_id", SqlDbType.NVarChar, 60);
        dat.SelectCommand.Parameters["@u_log_id"].Value = UserID;
        dat.SelectCommand.Parameters.Add("@type", SqlDbType.Int, 4);
        dat.SelectCommand.Parameters["@type"].Value = Type;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    //作废费用支付信息
    public Boolean DeleteFeePay(int id, int Is_Visible)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteFeePay", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@id", SqlDbType.Int);
        com.Parameters["@id"].Value = id;
        com.Parameters.Add("@type", SqlDbType.Int);
        com.Parameters["@type"].Value = Is_Visible;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    //确认费用支付信息
    public Boolean AuditFeePay(int ID, int AuditStat, string Auditor)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AuditFeePay", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@id", SqlDbType.NVarChar, 20);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@is_audit", SqlDbType.Int);
        com.Parameters["@is_audit"].Value = AuditStat;
        com.Parameters.Add("@auditor", SqlDbType.NVarChar, 60);
        com.Parameters["@auditor"].Value = Auditor;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    //增加费用支付信息
    public Boolean AddFeePay(string p_no, DateTime p_date, string r_no, string ry, decimal bczfje, string remark, string oper)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddFeePay", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@p_no", SqlDbType.NVarChar, 30);
        com.Parameters["@p_no"].Value = p_no;
        com.Parameters.Add("@p_date", SqlDbType.DateTime);
        com.Parameters["@p_date"].Value = p_date; 

        com.Parameters.Add("@r_no", SqlDbType.NVarChar, 30);
        com.Parameters["@r_no"].Value = r_no;
        com.Parameters.Add("@ry", SqlDbType.NVarChar, 30);
        com.Parameters["@ry"].Value = ry;        
        com.Parameters.Add("@bczfje", SqlDbType.Decimal);
        com.Parameters["@bczfje"].Value = bczfje;

        com.Parameters.Add("@remark", SqlDbType.NVarChar, 255);
        com.Parameters["@remark"].Value = remark;
        com.Parameters.Add("@oper", SqlDbType.NVarChar, 30);
        com.Parameters["@oper"].Value = oper;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    //修改费用支付信息
    public Boolean UpDateFeePay(int id, DateTime p_date, string Remark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_UpDateFeePay", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@id", SqlDbType.Int);
        com.Parameters["@id"].Value = id;
        com.Parameters.Add("@p_date", SqlDbType.DateTime);
        com.Parameters["@p_date"].Value = p_date;
        com.Parameters.Add("@remark", SqlDbType.NVarChar, 255);
        com.Parameters["@remark"].Value = Remark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    #endregion

}
